## logs module
import logging
import sys

# Set up logging
class Logs:
    def __init__(self, log_file= 'mainlog.txt'):
        self.logfile = log_file
    def error(self, message):
        logging.error(message)
        self.write('ERROR: ' + message)
    def warning(self, message):
        logging.warning(message)
        self.write('WARNING: ' + message)
    def info(self, message):
        logging.info(message)
        self.write('INFO: ' + message)
    def debug(self, message):
        logging.debug(message)
        self.write('DEBUG: ' + message)
    def write(self, message):
        with open(self.logfile, 'a') as f:
            f.write(message + '\n')
    def read(self):
        with open(self.logfile, 'r') as f:
            return f.read()
    def table(self, data):
        if isinstance(data, list):
            self.write("Table: " + data[0].__tablename__)
            self.write(data[0].__tableheader__())
            for item in data:
                self.write(item.__tablebody__())
        else:
            self.write(str(data))
    
        